<?php
date_default_timezone_set('PRC');
session_start();

$result = [
    'status' => 0,
    'data' => null,
    'message' => '未知错误'
];

include_once '../mysql/sql.php';
include_once 'select-fun.php';

if (isset($_SESSION['userid'])) {
    if (isset($sql) && $sql) {
        $params = [
            'userid' => $_SESSION['userid']
        ];

        $params['count'] = isset($_GET['count']) && $_GET['count'] > 0 ? $_GET['count'] : 5;
        
        $recently = incspe_recently($mysql, $params);
        if ($recently) {
            $result['status'] = 1;
            $result['data'] = $recently;
            $result['message'] = '获取数据成功';
        }
        else if ($recently === null) {
            $result['status'] = 1;
            $result['data'] = null;
            $result['message'] = '数据为空';
        }
        else {
            $result['status'] = 0;
            $result['message'] = '获取数据失败';
        };

        // 关闭连接
        $mysql->close();
    }
    else {
        $result['message'] = '数据库连接错误';
    };
}
else {
    $result['message'] = '用户未登入';
};

echo json_encode($result);
?>